# coding: utf-8
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from flask_login import LoginManager
from flask_uploads import UploadSet, configure_uploads
from config.config import Config   # 配置类

db = SQLAlchemy()
bootstrap = Bootstrap()
loginManager = LoginManager()

# loginManager 配置
loginManager.session_protection = 'strong'
loginManager.login_view = 'main.login'
loginManager.login_message = u'请登录后使用'
loginManager.login_message_category = "info"
# flask_uploads配置
UPLOAD_ALLOWED = tuple('jpg png rar zip doc docx ppt'.split())
files = UploadSet('files', UPLOAD_ALLOWED)


def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)
    Config.init_app(app)

    db.init_app(app)
    bootstrap.init_app(app)
    loginManager.init_app(app)
    configure_uploads(app, files)

    # 注册蓝本
    from .main import main as main_bluePrint
    app.register_blueprint(main_bluePrint)

    return app
